/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package netsend.server;

//imports
import com.mysql.jdbc.Driver;
import java.sql.DriverManager;
import java.util.Iterator;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
/*.threadPooling.ThreadPool;
import mixdownxbrowser.util.Functions;*/
import netsend.server.common.OSDetect;
import netsend.server.common.ReadConfigFiles;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.Category;
import org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel;
import snaq.db.ConnectionPool;

/**
 *
 * @author studio-x64
 */
public class Main {

    private static final Category log = Category.getInstance(Main.class.getName());
    public OSDetect osdetect = new OSDetect();    
    public static ConnectionPool sqlpool;  
    
    
    public static void main(String[] args) {
        String command = "";
        boolean serverRunning = false;
        
        if(args.length == 1){
            //command line args
            command = args[0];                 
            if(command.equals("/start")){                
                startServer();
                serverRunning =  true;
            }                    
            /*if(command.equals("/stop")){                
                stopServer();
                serverRunning =  false;
            }*/
        }      
        if(serverRunning != true){
            startServer();
        }
        //if (args.length != 1) {
            //System.out.println ("Incorrect number of params!");
            //System.out.println ("Usage: java Application command");  
            //System.exit(0);
        //}        
        //final ThreadPool threadpool = new ThreadPool(10);
        
        //needs to be moved off to a install dir path
        PropertyConfigurator.configure("log4jprops.txt");
        OSDetect.logSysInfo();
        
        /*try
        {
            Class c = Class.forName("com.mysql.jdbc.Driver");
            Driver driver = (Driver)c.newInstance();
            DriverManager.registerDriver(driver);
            String url = "jdbc:mysql://mysql.mixdownx.org/sets_db";
            sqlpool = new ConnectionPool("local",2, 2, 2, 180000, url, "setsadmin", "087Qsecosr");
        }
        catch (Exception ex)
        {
            log.error(ex);
        }*/

        //log.debug("Application started successfully...");        
        
        //Connection conn = db.dbConnect("jdbc:mysql://mysql.mixdownx.org/sets_db", "setsadmin", "087Qsecosr");
    }
    
    //start server method
    public static void startServer(){
        JFrame.setDefaultLookAndFeelDecorated(true);
        SwingUtilities.invokeLater(new Runnable(){
            public void run(){
                try{
                    UIManager.setLookAndFeel(new SubstanceGraphiteLookAndFeel());
                    NetsendServerUi serverUi = new NetsendServerUi();
                    serverUi.setVisible(true);
                }
                catch (Exception e){
                    e.printStackTrace();
                }
            }
        });
    }
    //stop server method
    public static void stopServer(){
        System.exit(-1);
    }
}
